from pms.common.views import PostFormula
from project.utils.update import update_project_by_view
from project.utils.profile import project_view
from project.utils.permission import assert_project_permissions


class API(PostFormula):

    def handle(self, req):
        pid = req['id']
        view = req['mod']
        assert_project_permissions(pid, self.user.id, [2])
        proj = update_project_by_view(pid, view)
        return self.success_respond(project_view(proj))
